package net.zigin.nhi.could.waste.service.impl;

import net.zigin.commons.util.ReflectUtil;
import net.zigin.commons.util.StringUtil;

import net.zigin.nhi.could.waste.aop.LoginAspect;
import net.zigin.nhi.could.waste.dao.SysUserHospitalMapper;
import net.zigin.nhi.could.waste.dao.WasteBaseMapper;
import net.zigin.nhi.could.waste.dto.WarnTimeDto;
import net.zigin.nhi.could.waste.model.WasteBase;
import net.zigin.nhi.could.waste.vo.TokenInfoBo;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.zigin.nhi.could.waste.dao.BaseMapper;
import net.zigin.nhi.could.waste.dao.WarnTimeMapper;
import net.zigin.nhi.could.waste.model.WarnTime;
import net.zigin.nhi.could.waste.service.WarnTimeService;

import javax.jms.Destination;

/*#################################################################*
# 说明:以下代码通过哲勤代码生成工具自动生成    
# 工具:GeneratorCode
# 作者:mgw1986                                                  
# 生成时间:2021-9-20 19:47:10                                               
##################################################################*/


/**
 * WarnTime服务实现类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: WarnTimeServiceImpl
 * @date 2021-9-20 19:47:10
 */
@Service
public class WarnTimeServiceImpl extends AbstractServiceImpl<WarnTime, String> implements WarnTimeService {
    @Autowired
    private WarnTimeMapper warnTimeMapper;
    @Autowired
    private SysUserHospitalMapper sysUserHospitalMapper;

    @Override
    public BaseMapper<WarnTime, String> getMapper() {
        return warnTimeMapper;
    }

    @Override
    public String saveOrUpdate(WarnTimeDto warnTimeDto) {
        WarnTime warnTime = ReflectUtil.copyProperties(warnTimeDto, WarnTime.class);
        if (StringUtil.isNullOrEmpty(warnTime.getId())) {
            TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
            String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
            warnTime.setId(StringUtil.get32UUID());
            warnTime.setHospitalBaseId(hospitalBaseId);
            warnTimeMapper.insert(warnTime);
        } else {
            warnTimeMapper.updateByPrimaryKeySelective(warnTime);
        }
        return warnTime.getId();
    }

    @Override
    public WarnTime getOne() {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        return warnTimeMapper.getOneByHospitalBaseId(hospitalBaseId);
    }
}